/**
 * 
 */
package com.wbcs.system.function.ifexpression;

import java.lang.reflect.Method;
import java.util.List;

import com.wbcs.exception.WbcsRuntimeException;
import com.wbcs.system.function.FuncAssistant;
import com.wbcs.system.function.IFuncDo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wbcs.util.Tools;

/**
 * 根据LIST集合是否有值判断执行逻辑的函数
 * @author hawkfly
 */
public class FuncIsLstSizeNot0 extends AbsIfFunc {
	
	private static Log log=LogFactory.getLog(FuncIsLstSizeNot0.class);
	
	public FuncIsLstSizeNot0(String funcName, String lstNameUpChain, String do1, String do2){
		super(funcName, lstNameUpChain, do1, do2);
	}
	
	@Override
	public boolean exec(Object ifAffectorObj, IFuncDo ido) {
		// TODO Auto-generated method stub
		List<?> lstReportData = null;
		try
		{
			lstReportData = (List<?>)ifAffectorObj;
		}
		catch(Exception e)
		{
			throw new WbcsRuntimeException("chain类型报表设置存取参数类型错误");
		}
		
		if(Tools.isEmpty(funcName, true))
		{
			log.warn("待执行函数未正确设定自定义函数名称");
			funcName = "isLstSizeNot0DefaultFunc";
		}
		
		if(Tools.isEmpty(do1, true))
		{
			log.error("函数" + funcName + "未取到执行条件1");
			return false;
		}
		
		if(Tools.isEmpty(do1, true))
		{
			log.error("函数" + funcName + "未取到执行条件2");
			return false;
		}
		
		try {
		
			if(lstReportData.size() > 0)
			{
				//执行条件1
				FuncAssistant.getInstance().execDoAction(ido, do1);
			}
			else
			{
				//执行条件2
				FuncAssistant.getInstance().execDoAction(ido, do2);
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		} 
		return true;
	}
}
